package com.xunjie.controller;

import cn.hutool.core.util.ObjectUtil;
import com.xunjie.domains.AjaxResult;
import com.xunjie.domains.Jobs;
import com.xunjie.service.JobsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("jobs")
@RequiredArgsConstructor
public class JobsController {
    private final JobsService jobsService;

    @GetMapping("select-all")
    public AjaxResult selectAll(){
        List<Jobs> jobsList = jobsService.selectAll();
        return AjaxResult.success(jobsList);
    }

    @GetMapping("select-count")
    public AjaxResult selectCount(){
        Long count = jobsService.count();
        return AjaxResult.success(count);
    }

    @PostMapping("update")
    @ResponseBody
    public AjaxResult update(@RequestBody Jobs jobs){
        if(ObjectUtil.isNull(jobs)){
            return AjaxResult.error("jobs不可为null");
        }

        int update = jobsService.update(jobs);
        if(update==1){
            return AjaxResult.success();
        }else{
            return AjaxResult.error();
        }

    }

}
